<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="/xlive/script/xlv.js"></script>
</head>
<body>
	<div id="topic_main" xlvobject="xlv.obj.borderLayout"
		xlvmethod="{
			styleFor:function(layout){
				var style={width:'100%',background:'url(/xlive/images/grayTexture.gif) left top repeat'};
				style.borderLeft='1px solid gray';
				style.borderTop='1px solid gray';
				style.borderRight='1px solid white';
				style.borderBottom='1px solid white';
				style.minHeight='480px';
				style.fontFamily='Arial';
				style.fontSize='12px';
				Element.setStyle(layout,style);
			}
		}"
	>
		<style type="text/css">
			#next_flip,#prev_flip,
			#page_control #page{
				background: url(/xlive/images/background_silver.jpg) repeat-x;
				border: 1px solid gray;
				cursor: default;
				padding: 2px 3px;
				margin: 2px 1px;
				color: gray;
				float: left;
			}
			#next_flip:hover,#prev_flip:hover,
			#page_control #page:hover{
				margin-top:0px;
				color:blue;
			}
			#page_control #page.current_page:hover,
			#page_control #page.current_page{
				margin-top:0px;
				color:blue;
				font-weight:bold;
			}
			#page_control.wait *{
				cursor:wait;
			}
		</style>
	
		<div xlvobject="xlv.obj.webObject" 
			 xlvprop="{name:'forum.topic',objectURL:'forum.topic',dataXPath:'properties.post-list.return.sql-statement.return.data',methodName:'topic'}"
			 xlvmethod="{
			 	initial:function(){
			 		var topic_main=xlv.util.findParent(this,{id:'topic_main'});
			 		var schema_key=topic_main.$P.caller.schema_key;
			 		var topic_key=topic_main.$P.caller.topic_key;
			 		this.$P.webObjectProperties={'topic':{'topic-key':topic_key}};
			 		this.$self('initial');
			 	}
			 }"
			 >
		</div>
		<div xlvobject="xlv.obj.rowset" 
			 xlvprop="{name:'forum.post',objectURL:'forum.post',dataXPath:'properties.list.return.sql-statement.return.data',methodName:'list'}"
			 xlvmethod="{
			 	initial:function(){
			 		var topic_main=xlv.util.findParent(this,{id:'topic_main'});
			 		var schema_key=topic_main.$P.caller.schema_key;
			 		var topic_key=topic_main.$P.caller.topic_key;
			 		this.$P.webObjectProperties={'list':{'topic-key':topic_key},'new-post':{'topic-key':topic_key}};
			 		this.$self('initial');
			 	}
			 }"
			 >
		</div>
		<div xlvobject="xlv.obj.webObject" xlvprop="{name:'fs.forum',objectURL:'fs.forum'}"></div>
		
		<div xlvobject="xlv.obj.dmTrigger"
	  	   xlvprop="{dmName:'forum.post',listener:{when:'afterModelChanged',notify:'setChanged',memoType:'create',memoMethods:'delete-post'}}"	
	  	    xlvmethod="{
	  	    	process:function(){
	  	    		var dm=this.getDataModel('forum.post');
	  	    		dm.webMethod('list');
	  	    	}
	  	    }"
	    ></div>	
	    
	    <div id="xlvid_north">
			<nobr>
			<img src='/xlive/images/forum/blue_pin.png'></img>
			<span xlvobject="xlv.obj.process" xlvprop="{title:' calalog'}"
				 xlvmethod="{
				 	process:function(options){
    					this.getBorderLayoutById('forum_main').setCenterPane('/xlive/forum/catalog.html',null,null,'bottom');
					}
				 }"
				>
			</span>
			<img src='/xlive/images/forum/forward.png'></img>
			<span xlvobject="xlv.obj.process" xlvprop="{title:' schema'}"
				 xlvmethod="{
				 	process:function(options){
				 		var main=xlv.util.findParent(this,{id:'topic_main'});
    					this.getBorderLayoutById('forum_main').setCenterPane('/xlive/forum/schema.html',{caller:{schema_key:main.$P.caller.schema_key}},null,'bottom');
					}
				 }"
				>
			</span>
			<img src='/xlive/images/forum/forward.png'><span style="font-size:13px;font-weight:bold">post</span></img>
			</nobr>
		</div>
	
 	
		<div id="xlvid_center">
			<div id="forum_topic" xlvobject="xlv.obj.pane" xlvprop="{glow:{enable:true},border:{enable:true}}">
				<div style="padding:8px">
				<table style="width:720px">
					<tr><td rowSpan="2"> 
							<div id="topic_icon" xlvobject="xlv.obj.img" xlvprop="{dmName:'forum.topic',dmPath:'properties.topic.return.sql-statement.return.data.r.TOPIC_ICON'}"
									xlvmethod="{
										styleFor:function(img){
											img.style.width='48px';img.style.height='48px';
										}
									}">
							</div>
						</td>
						<td> 
							<div style="font-weight:bold;font-size:large" id="topic_title" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.topic',dmPath:'properties.topic.return.sql-statement.return.data.r.TOPIC_TITLE'}"></div>
						</td>
						<td> 
							<div style="white-space:nowrap;font-size:10px;color:gray" id="topic_time" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.topic',dmPath:'properties.topic.return.sql-statement.return.data.r.TOPIC_TIME'}"
								xlvmethod="{
									mvc_valueToView:function(value){
										value=new Date().parseDate(value).formatDate('yyyy/MM/dd HH:mm:ss');
										xlv.util.setElementValue(this,value);
									}
								}"
							>
							</div>
							<div style="white-space:nowrap;font-size:10px;color:gray" id="user_key" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.topic',dmPath:'properties.topic.return.sql-statement.return.data.r.USER_KEY'}"
								xlvmethod="{
									mvc_valueFromModel:function(dm){
										var node=dm.getNode(this.$P.dmPath);
										return {user_key:xlv.util.getElementValue(node),user_name:dm.getValue('USER_NAME',node.parentNode)};
									},
									mvc_valueToView:function(value){
										var user_name=this.getObjectById('user_name');
										user_name.$V.user_key=value.user_key;
										user_name.setTitle(value.user_name);
									}
								}"
								>
				    			<div id="user_name" xlvobject="xlv.obj.process" style="text-decoration:underline;font-size:10px;color:gray"
				    					xlvmethod="{
				    						process:function(options){
				    							var prop={caller:{user_key:this.$V.user_key}};
				    							this.getDesktop().showPane('/xlive/forum/user.html',prop,null,{invoker:this,align:'right'});
			    							}
			    						}">
			    				</div>
			    			</div>
			    			<br/>
			    			<div style="white-space:nowrap;font-size:10px;color:gray" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.post',dmPath:'properties.list.return.sql-statement.return.data/@eofRows'}"
			    				xlvmethod="{
			    					mvc_valueToView:function(value){
			    						xlv.util.setElementValue(this, 'Total posts : '+value);
			    					}
			    				}"
			    			>
			    			</div>
						</td>
					</tr>
					<tr>
						<td width="100%">
							<div id="topic_text" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.topic',dmPath:'properties.topic.return.sql-statement.return.data.r.TOPIC_TEXT'}"
								 xlvmethod="{
								 	mvc_valueToView:function(value){
								 		this.innerHTML=value;
								 	}
								 }" 
								>
							</div>
						</td>
					</tr>
				</table>
				</div>
			</div>
			<div id="newPost" xlvobject="xlv.obj.dmProcess"
				 xlvprop="{dmName:'user',title:'new Post'}"
				 xlvmethod="{
				 	process:function(options){
				 		var dm=this.getDataModel('forum.post');
				 		dm.setValue('','properties.new-post.post-text');
				 		var user_key=0, user_icon='/xlive/images/forum/unknowMale.png';
				 		var user=this.getDataModel('user');
				 		if(user.isPasswordValid()){
				 			user_key=user.getValue('login.return.data.user-key');
				 			user_icon=user.getValue('login.return.data.user-icon');
				 		}
				 		dm.setValue(user_key,'properties.new-post.user-key');
				 		dm.setValue(user_icon,'properties.new-post.post-icon');
				 		var dm2=this.getDataModel('forum.topic');
				 		dm.setValue('Re : '+dm2.getValue('properties.topic.return.sql-statement.return.data.r.TOPIC_TITLE'),'properties.new-post.post-title');
				 		this.getDesktop().showPane('/xlive/forum/newPost.html',null,null,{invoker:this,align:'left'});
				 	},
			        mvc_enableControl:function(dm){
			           	//this.style.display=(dm.isPasswordValid()?'':'none');
			        }
				 }" 	
				>
				<img width="32" height="32" src="/xlive/images/forum/newtopic.png"/>
			</div>
			<div style="position:relative">
				<div style="position:relative;float:right" id="page_control" xlvobject="xlv.obj.viewer" xlvprop="{dmName:'forum.post',dmPath:'properties.list.return.sql-statement.return.data/@eofRows'}"
					xlvmethod="{
						flipPages:function(next){
							var pages=xlv.util.children(this,{id:'page'},null);
							var first=parseInt(pages[0].getTitle());
							if(next){
								first +=10;
								if(first+10 &gt; this.$V.total) first=this.$V.total-9;
							}else {
								first -=10;
								if(first &lt; 1) first=1;
							}
							var last=first+pages.length-1;
							for(var i=0; i &lt; pages.length;++i){
								pages[i].setTitle(first+i);
								if((first+i)==this.$V.current)Element.addClassName(pages[i],'current_page');
								else Element.removeClassName(pages[i],'current_page');
							}
							this.getObjectById('next_flip').style.display=(this.$V.total!=last)?'':'none';
							this.getObjectById('prev_flip').style.display=(first &gt; 1) ? '' :'none';
						},
						nextPage:function(offset){
							var page=parseInt(this.$V.current)+offset;
							if(page &lt; 1 || page &gt; this.$V.total) return;
							this.showPage(page);
						},
						showPage:function(page){
							if(Element.hasClassName(this,'wait')) return;
							Element.addClassName(this,'wait');
							var dm=this.getDataModel('forum.post');
							dm.setValue((page-1)*this.$V.row_fetch+1,'properties.list.row-from');
							dm.webMethod('list');
						},
						refreshPage:function(){
							this.showPage(this.$V.current);
						},
						mvc_valueToView:function(value){
							var dm=this.getDataModel('forum.post');
							var row_from=dm.getValue('properties.list.row-from');
							var row_fetch=dm.getValue('properties.list.row-fetch');
							this.$V.current=parseInt(row_from/row_fetch)+((row_from%row_fetch != 0)?1:0);
							this.$V.row_fetch=row_fetch;
							this.$V.total=Math.floor(value/row_fetch)+((value%row_fetch !=0)?1:0);
							this.$V.total=(!this.$V.total)? 1:this.$V.total;
							xlv.util.setElementValue(this.getObjectById('current_page'),this.$V.current);
							xlv.util.setElementValue(this.getObjectById('total_pages'),this.$V.total);
							var page_container=this.getObjectById('page_container');
							var pages=xlv.util.children(page_container,{id:'page'},null);
							var first=(pages.length!=0)?parseInt(pages[0].getTitle()):1;
							if(this.$V.current &gt; first+9) first=this.$V.current-9;
							else if(this.$V.current &lt; first) first=this.$V.current;
							var method={process:function(){
									var p=xlv.util.findParent(this,{id:'page_control'});
									p.showPage(this.getTitle());
								}};
							var last=first;	
							for(var i=0;i &lt; this.$V.total;++i){
								var page=(pages[i])? pages[i]:xlv.sys.newInstance(page_container,'process',null,method,null);
								page.setTitle(first+i);
								page.setAttribute('id','page');
								if(first+i==this.$V.current) Element.addClassName(page,'current_page');
								else Element.removeClassName(page,'current_page');
								last=first+i;
								if(i==9)break;
							}
							for(var i=this.$V.total; i &lt; 10; ++i){
								if(pages[i] &amp;&amp; pages[i].parentNode) pages[i].parentNode.removeChild(pages[i]);
							}
							this.getObjectById('next_flip').style.display=(this.$V.total!=last)?'':'none';
							this.getObjectById('prev_flip').style.display=(first &gt; 1) ? '' :'none';
							Element.removeClassName(this,'wait');
						}
					}"
					>
					<div style="float:right" id="prev_page" xlvobject="xlv.obj.process" xlvprop="{srcImg:'/xlive/images/forum/rightArrow.png'}"
						 xlvmethod="{
						 	process:function(){xlv.util.findParent(this,{id:'page_control'}).nextPage(1);		 	}
						 }"
						>
					</div>
					<div style="float:right;display:none" id="next_flip" xlvobject="xlv.obj.process" xlvprop="{title:'...'}"
						 xlvmethod="{
						 	process:function(){xlv.util.findParent(this,{id:'page_control'}).flipPages(true);}
						 }"
						>
					</div>
					<div style="float:right;position:relative;" id="page_container"></div>
					<div style="float:right;display:none" id="prev_flip" xlvobject="xlv.obj.process" xlvprop="{title:'...'}"
						 xlvmethod="{
						 	process:function(){xlv.util.findParent(this,{id:'page_control'}).flipPages(false);		 	}
						 }"
						>
					</div>
					<div style="float:right" id="prev_page" xlvobject="xlv.obj.process" xlvprop="{srcImg:'/xlive/images/forum/leftArrow.png'}"
						 xlvmethod="{
						 	process:function(){xlv.util.findParent(this,{id:'page_control'}).nextPage(-1);		 	}
						 }"
						>
					</div>
					<span style="float:right;margin-top:4px">Current page : <span id="current_page"></span> / <span id="total_pages"></span> Total pages </span>
				</div>
			</div>
			
			<div id="forum_post" xlvobject="xlv.obj.table" style="border-collapse:collapse;clear:both;"
				 xlvprop="{ selectable:false,dmName:'forum.post',showHeader:false,defaultStyle:false,
				 			columns:[{title:'AUTHOR',dmPath:'POST_TITLE'}]}"
				 xlvmethod="{
				 		styleForCell:function(row_no,cell_no,cell){
							cell.setAttribute('unselectable','on');
							var style={margin:'4px',backgroundColor:'transparent'};
							style.textAlign='left';
							Element.setStyle(cell,style);
							cell.style.padding='8px 4px';
						},
				 		mvc_valueFromModel:function(dm,row_no,cell_no){
							return dm.getNode(this.$P.columns[cell_no-1].dmPath,row_no).parentNode;
						}
				 }"
			    >
			    <table><tbody><tr><td>
			    <div id="post_pane" xlvobject="xlv.obj.pane" xlvprop="{glow:{enable:true},border:{enable:true,background:'white'}}" 
			    			 xlvmethod="{
			    			 	styleFor:function(root){
			    			 		root.style.backgroundColor='white';
			    			 	},
			    			 	mvc_valueToView:function(node,indexes){
			    			 		this.$V.postNode=node;
			    			 		xlv.util.setElementValue(this.getObjectById('post_title'),xlv.util.getXmlNodeValue('POST_TITLE',node));
			    			 		this.getObjectById('post_icon').src=xlv.util.getXmlNodeValue('POST_ICON',node);
			    			 		this.getObjectById('post_text').innerHTML=xlv.util.getXmlNodeValue('POST_TEXT',node);
			    			 		var user_name=this.getObjectById('user_name');
			    			 		user_name.setTitle(xlv.util.getXmlNodeValue('USER_NAME',node));
			    			 		user_name.$V.user_key=xlv.util.getXmlNodeValue('USER_KEY',node);
			    			 		var value=xlv.util.getXmlNodeValue('POST_TIME',node);
			    			 		value=new Date().parseDate(value).formatDate('yyyy/MM/dd HH:mm:ss');
			    			 		xlv.util.setElementValue(this.getObjectById('post_time'),value);
			    			 		var area=this.getObjectById('attach_area');
			    			 		while(area.firstChild)area.firstChild.parentNode.removeChild(area.firstChild);
			    			 		var workdir=xlv.util.getXmlNodeValue('POST_WORKDIR',node);
			    			 		var method={
			    			 			process:function(){
			    			 				var title=this.getTitle();
			    			 				var dm=this.getDataModel('fs.forum');
			    			 				dm.setValue(workdir,'properties.download.work-directory');
			    			 				var index=title.lastIndexOf('(');
			    			 				var name=title.substring(0,index);
			    			 				dm.setValue(name,'properties.download.name');
			    			 				this.$self('process');
			    			 			},
			    			 			mvc_enableControl:function(dm){
			    			 				return true;
			    			 			}
			    			 		};
			    			 		var attach=xlv.util.getXmlNodeValue('POST_ATTACH',node);
			    			 		var files=attach.split(';')
			    			 		for(var i=0;i &lt; files.length;++i){
			    			 			if(files[i].strip().length==0) continue;
			    			 			var prop={title:files[i],dmName:'fs.forum',methodName:'download'};
			    			 			var p=xlv.sys.newInstance(area,'downloader',prop,method);
			    			 			Element.setStyle(p,{display:'block',paddingLeft:'12px'});
			    			 		}
			    			 		if(area.firstChild){
			    			 			area.insertBefore(document.createElement('hr'),area.firstChild);
			    			 			var div=document.createElement('div');
			    			 			area.insertBefore(div,area.firstChild);
			    			 			div.innerHTML='Attach :';
			    			 			Element.setStyle(div,{fontWeight:'bold',fontStyle:'italic',fontSize:'9px'});
				    			 	}
			    			 	}
			    			 }">
			    	<table style="width:100%">		    	
			    	<tbody>
			    		<tr>
			    			<td width="80px" style="vertical-align:top;text-align:center">
			    				<img width="64" id="post_icon"></img>
			    				<span id="user_name" style="white-space:nowrap;font-size:10px;color:gray;text-align:left" xlvobject="xlv.obj.process"
			    					xlvmethod="{
			    						process:function(options){
				    						var prop={caller:{user_key:this.$V.user_key}};
				    						this.getDesktop().showPane('/xlive/forum/user.html',prop,null,{invoker:this,align:'left'});
			    						}
			    					}"
			    				>
			    				</span>
			    				<div style="font-size:10px;color:gray;">
			    				</div>
			    			</td>
			    			<td><div>
			    					<div style="border:1px solid #ACA899;background-color:#F4F4FF;padding:8px;margin:0 4px">
			    						<div id="post_title" style="font-weight:bold;font-size:16px;padding:2px"></div>
			    						<div>
			    							<span id="post_time" style="white-space:nowrap;font-size:10px;color:gray;text-align:right" ></span>
			    							<span title="delete post" xlvobject="xlv.obj.dmProcess" style="display:none"
			    							 			 xlvprop="{dmName:'user',srcImg:'/xlive/images/forum/page_delete.png',title:''}"
			    								    	 xlvmethod="{
			    								    	 	process:function(options){
			    								    	 		var node=xlv.util.findParent(this,{id:'post_pane'}).$V.postNode;
			    								    	 		var post_key=xlv.util.getXmlNodeValue('POST_KEY',node);
			    								    	 		var post_title=xlv.util.getXmlNodeValue('POST_TITLE',node);
			    								    	 		if(!confirm('delete this post : \n\n'+post_title)) return;
			    								    	 		var dm=this.getDataModel('forum.post');
			    								    	 		dm.setValue(post_key,'properties.delete-post.post-key');
			    								    	 		dm.webMethod('delete-post');
			    								    	 	},
			    							   	 			mvc_enableControl:function(dm){
			    							   	 				var valid;
			    							   	 				if(vaild=dm.isPasswordValid()){
			    							   	 					if(!(valid=dm.isForumAdmin())){
			    							   	 						var user_key=dm.getValue('login.return.data.user-key');
			    							   	 						var dmtopic=this.getDataModel('forum.topic');
			    							   	 						var schema_user=dmtopic.getValue('properties.topic.return.sql-statement.return.data.r.SCHEMA_USER_KEY');
			    							   	 						valid=(user_key==schema_user);
			    							   	 					}
			    							   	 				}
			    							   	 				this.style.display=((valid)?'':'none');
			           										}
			    								    	 }"
			    								    >
			    							</span>
			    							<div id="newPost" xlvobject="xlv.obj.dmProcess" style="float:right"
												xlvprop="{dmName:'user',title:'Reply'}"
				 								xlvmethod="{
												 	process:function(options){
												 		var node=xlv.util.findParent(this,{id:'post_pane'}).$V.postNode;
				 										var dm=this.getDataModel('forum.post');
				 										var user=this.getDataModel('user');
				 										var user_key=0,user_icon='/xlive/images/forum/unknowMale.png';
				 										if(user.isPasswordValid()){
				 											user_key=user.getValue('login.return.data.user-key')
				 											user_icon=user.getValue('login.return.data.user-icon');
				 										}
				 										dm.setValue(user_key,'properties.new-post.user-key');
				 										dm.setValue(user_icon,'properties.new-post.post-icon');
				 										dm.setValue('Re : '+xlv.util.getXmlNodeValue('POST_TITLE',node),'properties.new-post.post-title');
				 										var quote='&lt;blockquote style=&quot;color:gray&quot;  &gt; '+
				 										          xlv.util.getXmlNodeValue('USER_NAME',node)+'  wrote : &lt;br/&gt;'+
				 												   xlv.util.getXmlNodeValue('POST_TEXT',node)+'&lt;/blockquote&gt; &lt;p/&gt; '
				 										dm.setValue(quote,'properties.new-post.post-text');
				 										this.getDesktop().showPane('/xlive/forum/newPost.html',null,null,{invoker:this,align:'right'});
				 									},
			        								mvc_enableControl:function(dm){
			           									//this.style.display=(dm.isPasswordValid()?'':'none');
			        								}
				 								}" 	
											>
												<img width="32" height="32" src="/xlive/images/forum/newtopic.png"/>
											</div>
			    						</div>
			    					</div>
			    					<div style="padding:8px">
			    						<div id="post_text"></div>
			    					</div>
			    					<div id="attach_area" style="padding:0 8px 0 0;">
			    					</div>
			    					<div style="padding:8px">
			    						<img style="float:right" src="/xlive/images/forum/eject_up.png" onClick="window.scrollTo(0,0)"></img>
			    					</div>
			    					
			    				</div>
			    			</td>
			    		</tr>
			    	</tbody>
			    	</table>	
			    </div>
			    </td></tr></tbody></table>
			</div>
		</div>
		


		<div id="xlvid_south">
			<!-- <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'forum.topic'}"></div>-->
			<!-- <div xlvobject="xlv.obj.tree" xlvprop="{dmName:'forum.post'}"></div>-->
		</div>
	</div>
</body>
</html>
